package adapter_patten;

/**
 * 适配器模式:
 */
public class Adapter {
  public static void main(String[] args) {
    Mp4 mp4 = new VideoPlayer();
    mp4.playMp4();
    Avi avi = new FormatFactory();
    avi.playAvi();

    //----------------------------------------
    //推荐
    Rvmb rvmb = new FormatFactory2(new VideoPlayer());
    rvmb.playRmvb();
  }
}

//1.定义接口
interface Mp4{
  void playMp4();
}

interface Avi{
  void playAvi();
}


interface Rvmb{
  void playRmvb();
}

//2.实现要转换的成为接口，如我要转换成MP4
class VideoPlayer implements Mp4{

  public void playMp4() {
    System.out.println("播放Mp4格式的视频文件.");
  }
}

/**
 * 1.类适配器模式
 */
//3.继承要转换的目标的实现；实现转换源
class  FormatFactory extends VideoPlayer implements Avi{
  public void playAvi() {
    playMp4();
  }
}

/**
 * 2.对象适配器模式
 */
class FormatFactory2 implements Rvmb{

  private Mp4 mp4;

  public FormatFactory2(Mp4 mp4) {
    this.mp4 = mp4;
  }

  public void playRmvb() {
    mp4.playMp4();
  }
}



